// 使用 promise 写法
const sleep = function (time) {
  return new Promise((resolve, reject) => {
    setTimeout(resolve, time);
  });
};

sleep(1000).then(() => {
  console.log("go");
});

function* sleepGenerator(time) {
  yield new Promise((resolve, reject) => {
    setTimeout(resolve, time);
  });
  console.log("处于子协程");
}

let generator = sleepGenerator(1000);

generator.next().value.then(() => {
  console.log("处于父协程");
  generator.next();
});
